package com.dinghui.ebookbag.module.middle.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.dinghui.ebookbag.R;
import com.dinghui.ebookbag.enity.User;

import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by Jmh
 * on 2021-03-11
 */
public class OnlineStuAdapter extends BaseAdapter {
    private Context context;
    private LayoutInflater mInflater;
    private List<User> datas;

    public OnlineStuAdapter(Context context, List<User> datas) {
        this.context = context;
        this.datas = datas;
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder vh;
        if (convertView == null) {
            vh = new ViewHolder();
            convertView = mInflater.inflate(R.layout.online_stu_item, null);
            vh.tv = convertView.findViewById(R.id.osi_tv);
            vh.civ = convertView.findViewById(R.id.osi_civ);
            convertView.setTag(vh);

        } else {
            vh = (ViewHolder) convertView.getTag();
        }

        User user = datas.get(position);
        vh.civ.setImageResource(user.getAvatar());
        vh.tv.setText(user.getName());
        return convertView;
    }

    class ViewHolder {
        private TextView tv;
        private CircleImageView civ;
    }
}
